package bingo.web.mvc.exception;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Jan 21, 2009 12:30:17 PM
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:异常处理类
 * ChangeLog:
 */
public class ExceptionHandler implements IExceptionHandler {
	private static final Log log = LogFactory.getLog(ExceptionHandler.class);
	private String exceptionPage;
	

	public String getExceptionPage() {
		return exceptionPage;
	}


	public void setExceptionPage(String exceptionPage) {
		this.exceptionPage = exceptionPage;
	}


	public void processException(HttpServletRequest request,
			HttpServletResponse response, Exception exeception) throws ServletException, IOException {
		log.error("响应Http请求时出现错误",exeception);
		saveException(request, response, exeception);
		String errorPage = getExceptionPage(request, response, exeception);
		request.getRequestDispatcher(errorPage).forward(request, response);
		
	}


	public String getExceptionPage(HttpServletRequest request,
			HttpServletResponse response, Exception exeception) {
		return exceptionPage;
	}


	public void saveException(HttpServletRequest request,
			HttpServletResponse response, Exception exeception) {
		request.setAttribute("global_exception_key", exeception);
	}
	
	
	
}
